/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package orm;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;

public class DiagnoseDAO {
	public static Diagnose loadDiagnoseByORMID(int idDiag) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return loadDiagnoseByORMID(session, idDiag);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Diagnose getDiagnoseByORMID(int idDiag) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return getDiagnoseByORMID(session, idDiag);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Diagnose loadDiagnoseByORMID(int idDiag, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return loadDiagnoseByORMID(session, idDiag, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Diagnose getDiagnoseByORMID(int idDiag, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return getDiagnoseByORMID(session, idDiag, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Diagnose loadDiagnoseByORMID(PersistentSession session, int idDiag) throws PersistentException {
		try {
			return (Diagnose) session.load(orm.Diagnose.class, new Integer(idDiag));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Diagnose getDiagnoseByORMID(PersistentSession session, int idDiag) throws PersistentException {
		try {
			return (Diagnose) session.get(orm.Diagnose.class, new Integer(idDiag));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Diagnose loadDiagnoseByORMID(PersistentSession session, int idDiag, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Diagnose) session.load(orm.Diagnose.class, new Integer(idDiag), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Diagnose getDiagnoseByORMID(PersistentSession session, int idDiag, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Diagnose) session.get(orm.Diagnose.class, new Integer(idDiag), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Diagnose[] listDiagnoseByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return listDiagnoseByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Diagnose[] listDiagnoseByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return listDiagnoseByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Diagnose[] listDiagnoseByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Diagnose as Diagnose");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Diagnose[]) list.toArray(new Diagnose[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Diagnose[] listDiagnoseByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Diagnose as Diagnose");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Diagnose[]) list.toArray(new Diagnose[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Diagnose loadDiagnoseByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return loadDiagnoseByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Diagnose loadDiagnoseByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return loadDiagnoseByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Diagnose loadDiagnoseByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Diagnose[] diagnoses = listDiagnoseByQuery(session, condition, orderBy);
		if (diagnoses != null && diagnoses.length > 0)
			return diagnoses[0];
		else
			return null;
	}
	
	public static Diagnose loadDiagnoseByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Diagnose[] diagnoses = listDiagnoseByQuery(session, condition, orderBy, lockMode);
		if (diagnoses != null && diagnoses.length > 0)
			return diagnoses[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateDiagnoseByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return iterateDiagnoseByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateDiagnoseByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return iterateDiagnoseByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateDiagnoseByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Diagnose as Diagnose");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateDiagnoseByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Diagnose as Diagnose");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Diagnose createDiagnose() {
		return new orm.Diagnose();
	}
	
	public static boolean save(orm.Diagnose diagnose) throws PersistentException {
		try {
			orm.Taller1PDSPersistentManager.instance().saveObject(diagnose);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean delete(orm.Diagnose diagnose) throws PersistentException {
		try {
			orm.Taller1PDSPersistentManager.instance().deleteObject(diagnose);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean deleteAndDissociate(orm.Diagnose diagnose)throws PersistentException {
		try {
			if(diagnose.getBabyMonitorCodSystem() != null) {
				diagnose.getBabyMonitorCodSystem().setDiagnose(null);
			}
			
			if(diagnose.getPacientidPaciente() != null) {
				diagnose.getPacientidPaciente().setDiagnose(null);
			}
			
			if(diagnose.getSolution() != null) {
				diagnose.getSolution().setDiagnoseidDiag(null);
			}
			
			return delete(diagnose);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean deleteAndDissociate(orm.Diagnose diagnose, org.orm.PersistentSession session)throws PersistentException {
		try {
			if(diagnose.getBabyMonitorCodSystem() != null) {
				diagnose.getBabyMonitorCodSystem().setDiagnose(null);
			}
			
			if(diagnose.getPacientidPaciente() != null) {
				diagnose.getPacientidPaciente().setDiagnose(null);
			}
			
			if(diagnose.getSolution() != null) {
				diagnose.getSolution().setDiagnoseidDiag(null);
			}
			
			try {
				session.delete(diagnose);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean refresh(orm.Diagnose diagnose) throws PersistentException {
		try {
			orm.Taller1PDSPersistentManager.instance().getSession().refresh(diagnose);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean evict(orm.Diagnose diagnose) throws PersistentException {
		try {
			orm.Taller1PDSPersistentManager.instance().getSession().evict(diagnose);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Diagnose loadDiagnoseByCriteria(DiagnoseCriteria diagnoseCriteria) {
		Diagnose[] diagnoses = listDiagnoseByCriteria(diagnoseCriteria);
		if(diagnoses == null || diagnoses.length == 0) {
			return null;
		}
		return diagnoses[0];
	}
	
	public static Diagnose[] listDiagnoseByCriteria(DiagnoseCriteria diagnoseCriteria) {
		return diagnoseCriteria.listDiagnose();
	}
}
